﻿@inherits AdminCompontentBase

<MCard Class="d-flex flex-column" Style="cursor: unset;" MinHeight=Height Hover>
    <MCardTitle Class="pb-1 px-0 pt-1">
        <MListItem>
            <MListItemAvatar Height=40 Width=40 MinHeight="40" MinWidth="40">
                <MImage Src="@Team.Avatar"></MImage>
            </MListItemAvatar>
            <MListItemContent Class="pb-3">
                <MListItemTitle Class="d-flex justify-space-between align-center">
                    <div>
                        <span class="body2 masa-text-3-1">@T("Member") : @Team.MemberCount </span>
                        <MListItemSubtitle Class="h7 masa-text-1-2">@Team.Name</MListItemSubtitle>
                    </div>
                    <SButton OnClickStopPropagation Icon OnClick="HandleEditClick">
                        <SIcon Tooltip="@T("Edit")" Class="emphasis2--text">@IconConstants.Update</SIcon>
                    </SButton>
                </MListItemTitle>
                
            </MListItemContent>
        </MListItem>
    </MCardTitle>
    <MCardText Class="flex-grow-1" Style="text-align: justify;max-height:100px;">
        <span class="subtitle masa-text-2-1" style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;">
            @Team.Description
        </span>
    </MCardText>
    <MCardActions Class="px-4">
        <div class="avatar-list-stacked">
            @{var index = 1;}
            @foreach (var adminAvatar in Team.AdminAvatar) 
            {
                <MAvatar Size="40">
                    <MImage Width="40" Height="40" Src="@adminAvatar"></MImage>
                </MAvatar>
                
                if (index >= _showAdminAvatarCount)
                {
                    <MAvatar Size="40" Class="fill-disabled primary--text">
                        +@(Team.AdminAvatar.Count - _showAdminAvatarCount)
                    </MAvatar>
                    break;
                }
                index++;
            }
        </div>
        <MSpacer />
        <span class="body2 masa-text-3-1">@T("Edit In") @Team.ModificationTime.Humanize(culture:I18n.Culture)</span>
        <span class="mx-2" style="color:#E2E7F4">|</span>
        <span class="body2 masa-text-1-2">@Team.Modifier</span>
    </MCardActions>
</MCard>

@code {
    [Parameter]
    public EventCallback OnEditClick { get; set; }

    [Parameter]
    public int Height { get; set; } = 230;

    [EditorRequired]
    [Parameter]
    public TeamDto Team { get; set; } = null!;

    private int _showAdminAvatarCount = 5;

    private async Task HandleEditClick()
    {
        if (OnEditClick.HasDelegate)
        {
            await OnEditClick.InvokeAsync();
        }
    }
}